import {request, handleFetchResultNotification, REQUEST_TYPE} from '../utils';
import stringify from 'Shared/utils/stringify';
import {formatMessage} from './intl';
const baseUrl = '/parts/api/v1';
import * as dto from './DTO';

const getInitDataDesc = formatMessage({
    id: 'api.message.getInitDataDesc',
    defaultMessage: '初始化查询'
});
const getListDesc = formatMessage({
    id: 'api.message.getListDesc',
    defaultMessage: '查询备件业务数据修改日志列表'
});
const updateDeliveryDesc = formatMessage({
    id: 'api.message.updateDeliveryDesc',
    defaultMessage: '交货单状态修改'
});
const deliveryOrderQueryDesc = formatMessage({
    id: 'api.message.deliveryOrderQueryDesc',
    defaultMessage: '备件交货单查询'
});
const updatePartSaleOrderDesc = formatMessage({
    id: 'api.message.updatePartSaleOrderDesc',
    defaultMessage: '销售订单修改'
});
const getPartSaleOrdersDesc = formatMessage({
    id: 'api.message.getPartSaleOrdersDesc',
    defaultMessage: '销售订单查询'
});

//初始化
export const getInitData = () => request(`${baseUrl}/ui/partDataModifyLog/init`, null, dto.InitDataStruct)
    .then(handleFetchResultNotification(REQUEST_TYPE.initQuery, getInitDataDesc));

// 查询
export const getList = bodyCondition => {
    const queryString = stringify(bodyCondition);
    return request(`${baseUrl}/partDataModifyLogs?${queryString}`, null, dto.List)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, getListDesc));
};
// 交货单状态修改
export const deliveryData = data => request(`${baseUrl}/partDataModifyLogs`, {
    method: 'POST',
    headers: {'Content-Type': 'application/json'},
    body: JSON.stringify(data)
}).then(handleFetchResultNotification(REQUEST_TYPE.submit, updateDeliveryDesc));

//交货单查询
export const deliveryOrderQuery = pageOption => {
    const queryString = stringify(pageOption);
    return request(`${baseUrl}/deliveryOrders/forPartDataModifyLog?${queryString}`, null, dto.SelectList)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, deliveryOrderQueryDesc));
};
// 销售订单状态修改
export const partSaleOrderData = data => request(`${baseUrl}/partDataModifyLogs/saleOrder`, {
    method: 'POST',
    headers: {'Content-Type': 'application/json'},
    body: JSON.stringify(data)
}).then(handleFetchResultNotification(REQUEST_TYPE.submit, updatePartSaleOrderDesc));

//销售订单查询
export const getPartSaleOrders = pageOption => {
    const queryString = stringify(pageOption);
    return request(`${baseUrl}/partSaleOrders/forPartDataModifyLog?${queryString}`, null, dto.SelectList)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, getPartSaleOrdersDesc));
};
